<template>
    <div class="caretWrapper">
        <v-head></v-head>
        <div class="contentArea">
            <v-sidebar></v-sidebar>
            <div class="sidebar_right" :class="{'content-collapse':collapse}">
                <v-tags></v-tags>
                <div class="content">
                    <transition name="move" mode="out-in">
                        <keep-alive :include="tagsList">
                            <router-view></router-view>
                        </keep-alive>
                    </transition>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import vHead from '../../components/header.vue'
    import vSidebar from '../../components/sidebar'
    import vTags from '../../components/tages'
    import bus from '../../common/bus'
    export default {
        name: "home",
        components: {
            vHead,
            vSidebar,
            vTags
        },
        data () {
            return {
                collapse: false,
                tagsList: []
            }
        },
        created() {
            bus.$on('collapse-content', msg => {
                this.collapse = msg;
            });
            // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
            bus.$on('tags', msg => {
                let arr = [];
                for (let i = 0, len = msg.length; i < len; i++) {
                    msg[i].name && arr.push(msg[i].name);
                }
                this.tagsList = arr;
            });

        },
    }
</script>

<style lang="scss" scoped>
.caretWrapper {
    width: 100%;
    height: 100%;
    .contentArea {
        height: 100%;
        display: flex;
        .sidebar_right {
            flex: 1;
            height: 100%;
            -webkit-transition: left .3s ease-in-out;
            transition: left .3s ease-in-out;
            background: #f0f0f0;
            .content {
                width: auto;
                height: 100%;
                padding: 12px;
                box-sizing: border-box;
            }
        }
    }
}
</style>